package jee.boot.module.act.rest;

import jee.boot.common.basic.CrudController;
import jee.boot.common.basic.result.ResponseMessage;
import jee.boot.common.basic.result.Result;
import jee.boot.entity.activiti.ActProcDef;
import jee.boot.module.act.service.ActProcDefService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * 流程定义
 */
@RestController
@RequestMapping(value = "/procdef")
public class ActProcDefRestController extends CrudController<ActProcDefService, ActProcDef> {
    /**
     * 流程部署(文件)
     * @param category
     * @param file
     * @return
     */
    @PostMapping("/deploy")
    public ResponseMessage<Process> deploy(@RequestParam("category") String category, @RequestParam("file") MultipartFile file) {
        if (file == null) {
            return Result.requestError("上传的文件为空");
        }
        service.deploy(category,file);
        return Result.success();
    }

    /**
     * 变更流程状态
     * @param entity
     * @return
     */
    @PostMapping("/updateStatus")
    public ResponseMessage<ActProcDef> updateStatus(@RequestBody ActProcDef entity) {
        service.updateStatus(entity);
        return Result.success();
    }

    /**
     * 删除部署的流程，级联删除流程实例
     * @param entity
     * @return
     */
    @PostMapping("/delete")
    public ResponseMessage<Object> delete(@RequestBody ActProcDef entity) {
        service.deleteDeployment(entity);
        return Result.success();
    }

    /**
     * 转换模型
     * @param entity
     * @return
     */
    @PostMapping("/toModel")
    public ResponseMessage<ActProcDef> convertToModel(@RequestBody ActProcDef entity) {
        service.convertToModel(entity);
        return Result.success();
    }

    /**
     * 导出 xml
     * @param entity
     * @param response
     */
    @GetMapping (value="/exportXml")
    public void exportXml(ActProcDef entity, HttpServletResponse response) {
        service.exportXml(entity,response);
    }

    /**
     * 导出png
     * @param entity
     * @param response
     */
    @GetMapping (value="/exportPng" )
    public void exportPng(ActProcDef entity, HttpServletResponse response) {
        service.exportPng(entity,response);
    }

}
